package com.ynsj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ynsj.mapper.ConfigMapper;
import com.ynsj.domain.Config;
import com.ynsj.service.ConfigService;
import org.springframework.util.StringUtils;

@Service
public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> implements ConfigService{

    /**
     * 分页查询系统参数配置
     *
     * @param page
     * @param type
     * @param coed
     * @param name
     * @return
     */
    @Override
    public Page<Config> findByPage(Page<Config> page, String type, String coed, String name) {
        page.addOrder(OrderItem.desc("created"));
        return page(page,new LambdaQueryWrapper<Config>()
                .like(!StringUtils.isEmpty(type),Config::getType,type)
                .like(!StringUtils.isEmpty(coed),Config::getCode,coed)
                .like(!StringUtils.isEmpty(name),Config::getName,name));
    }

    /**
     * 通过规则code查询签名
     *
     * @param sign 签名的code
     * @return
     */
    @Override
    public Config getConfigByCode(String sign) {
        return getOne(new LambdaQueryWrapper<Config>()
                .eq(!StringUtils.isEmpty(sign),Config::getCode,sign));
    }
}
